﻿//
// Created by wellwei on 2023/12/5.
//
#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <algorithm>
#include "FileHandler.h"            //文件操作头文件
#include "Manager.h"

Manager* Manager::instance = nullptr; //为Manager类的静态成员变量instance分配内存//标志尚未创建实例 野指针

void Manager::initData() {               // 初始化数据
	std::cout << "正在读取数据..." << std::endl;

	std::filesystem::path currentPath = std::filesystem::current_path();         // 获取文件路径
	std::filesystem::path booksUrl = currentPath / "src/books";//先调用 std::filesystem::current_path() 获取当前工作目录的路径，然后使用 / 操作符将其与 "src/books" 进行拼接，形成一个新的路径
	std::filesystem::path recordsUrl = currentPath / "src/records";

	std::filesystem::path absolutePath = std::filesystem::absolute(booksUrl);        // absolute获取绝对路径
	std::filesystem::path absolutePath2 = std::filesystem::absolute(recordsUrl);        // 获取绝对路径

	// 文件操作
	FileHandler fileHandler(absolutePath, absolutePath2);                                   // 传入文件路径
	fileHandler.loadData(books, borrowingRecords);                    // 读取数据
	for (auto& book : books) {                     // 为每本书建立索引
		bookIndex[book.getISBN()] = book.getIndex();
	}
}

void Manager::Exit() {                               // 保存数据并退出
	std::cout << "正在保存数据..." << std::endl;

	std::filesystem::path currentPath = std::filesystem::current_path();         // 获取文件路径
	std::filesystem::path booksUrl = currentPath / "src/books";
	std::filesystem::path recordsUrl = currentPath / "src/records";

	std::filesystem::path absolutePath = std::filesystem::absolute(booksUrl);        // 获取绝对路径
	std::filesystem::path absolutePath2 = std::filesystem::absolute(recordsUrl);        // 获取绝对路径

	// 文件操作
	FileHandler fileHandler(absolutePath, absolutePath2);            // 传入文件路径
	fileHandler.saveData(books, borrowingRecords);                   // 保存数据
}

void Manager::addBookSingle() {
	std::string name, author, ISBN, publisher, publishDate, barcode, location;
	double price;
	int classification, total;
	std::cout << "----------单个添加图书----------" << std::endl;
	std::cout << "--请按照以下格式输入图书信息：" << std::endl;
	std::cout << "--书名 作者 ISBN 号 定价 出版社 出版日期 条码号 分类号 馆藏地 书籍总量" << std::endl;
	std::cin >> name >> author >> ISBN >> price >> publisher >> publishDate >> barcode >> classification >> location
		>> total;
	Book book(name, author, ISBN, price, publisher, publishDate, barcode, classification, location, total, total);
	std::cout << "确定添加吗？(y/n)";
	char choice;
	std::cin >> choice;
	if (choice == 'y') {
		if (bookIndex[ISBN] == 0) {                 // 如果该书不存在，则添加
			book.setIndex((int)books.size() + 1);
			books.push_back(book);
			bookIndex[ISBN] = book.getIndex();
		}
		else {                                      // 如果该书已存在，则更新现有书籍的总量和可用量
			Book& oldBook = books[bookIndex[ISBN] - 1];
			oldBook.setTotal(oldBook.getTotal() + total);
			oldBook.setAvailable(oldBook.getAvailable() + total);
		}
		std::cout << "添加成功！" << std::endl;
	}
	else {
		std::cout << "添加失败！" << std::endl;
	}
}

void Manager::addBookBatch() {
	std::vector<Book> tmpBooks;
	std::string name, author, ISBN, publisher, publishDate, barcode, location;
	double price;
	int classification, total;
	std::cout << "----------批量添加图书----------" << std::endl;
	std::cout << "--请按照以下格式输入图书信息：" << std::endl;
	std::cout << "--书名 作者 ISBN 号 定价 出版社 出版日期 条码号 分类号 馆藏地 书籍数量" << std::endl;
	std::cout << "--输入 0 结束输入" << std::endl;
	while (true) {
		std::cin >> name;
		if (name == "0") {
			break;
		}
		std::cin >> author >> ISBN >> price >> publisher >> publishDate >> barcode >> classification >> location
			>> total;
		Book book(name, author, ISBN, price, publisher, publishDate, barcode, classification, location, total, total);
		tmpBooks.push_back(book);
	}
	std::cout << "确定添加吗？(y/n)";
	char choice;
	std::cin >> choice;
	if (choice == 'y') {
		for (auto& book : tmpBooks) {
			if (bookIndex[book.getISBN()] == 0) {                 // 如果该书不存在，则添加
				book.setIndex((int)books.size() + 1);
				books.push_back(book);
				bookIndex[book.getISBN()] = book.getIndex();
			}
			else {                                      // 如果该书已存在，则修改
				Book& oldBook = books[bookIndex[book.getISBN()] - 1];
				oldBook.setTotal(oldBook.getTotal() + book.getTotal());
				oldBook.setAvailable(oldBook.getAvailable() + book.getTotal());
			}
		}
		std::cout << "添加成功！" << std::endl;
	}
	else {
		std::cout << "添加失败！" << std::endl;
	}
}

void Manager::deleteBook() {
	std::string Tiaoma;
	std::cout << "请输入要删除书籍的条码号或 ISBN 码，输入 0 退出" << std::endl;
	while (true) {
		std::cin >> Tiaoma;
		if (Tiaoma == "0") break;
		auto it = std::find_if(books.begin(), books.end(), [Tiaoma](Book& book) {
			return book.getBarcode() == Tiaoma || book.getISBN() == Tiaoma;
			});
		if (it != books.end()) {
			it->showInfo1();
			std::cout << "确定删除吗？(y/n)";
			char choice;
			std::cin >> choice;
			if (choice == 'y') {
				books.erase(it);
				std::cout << "书籍已成功删除" << std::endl;
			}
			else {
				std::cout << "已取消删除" << std::endl;;
			}
		}
		else {
			std::cout << "找不到要删除的书籍，请重新输入" << std::endl;
		}
	}
}

void Manager::modifyBook() {//修改书籍
	std::string mark;
	std::cout << "请输入要修改书籍的条码号或 ISBN 码，输入 0 退出" << std::endl;
	while (true) {
		std::cin >> mark;
		getchar();
		if (mark == "0") break;
		auto it = std::find_if(books.begin(), books.end(), [mark](Book& book) {//std::find_if: 算法函数，用于在指定范围内查找第一个满足指定条件的元素。返回一个指向找到的元素的迭代器
			//[mark](Book& book) {...}: 是一个 lambda 表达式，定义了查找条件
			//mark 是外部变量，通过 lambda 的捕获列表[mark] 引入
			return book.getBarcode() == mark || book.getISBN() == mark;
			});
		if (it != books.end()) {
			it->showInfo1();
			std::string name, author, ISBN, publisher, publishDate, barcode, location, price, classification, total;
			std::cout << "请输入修改后的书籍信息，不修改的信息请直接回车" << std::endl;
			std::cout << "--书名（" << it->getName() << "）：";
			getline(std::cin, name);
			if (name.empty()) name = it->getName();
			std::cout << "--作者（" << it->getAuthor() << "）：";
			getline(std::cin, author);
			if (author.empty()) author = it->getAuthor();
			std::cout << "--ISBN 号（" << it->getISBN() << "）：";
			getline(std::cin, ISBN);
			if (ISBN.empty()) ISBN = it->getISBN();
			std::cout << "--定价（" << it->getPrice() << "）：";
			getline(std::cin, price);
			if (price.empty()) price = std::to_string(it->getPrice());
			std::cout << "--出版社（" << it->getPublisher() << "）：";
			getline(std::cin, publisher);
			if (publisher.empty()) publisher = it->getPublisher();
			std::cout << "--出版日期（" << it->getPublishDate() << "）：";
			getline(std::cin, publishDate);
			if (publishDate.empty()) publishDate = it->getPublishDate();
			std::cout << "--条码号（" << it->getBarcode() << "）：";
			getline(std::cin, barcode);
			if (barcode.empty()) barcode = it->getBarcode();
			std::cout << "--分类号（" << it->getClassification() << "）：";
			getline(std::cin, classification);
			if (classification.empty()) classification = std::to_string(it->getClassification());
			std::cout << "--馆藏地（" << it->getLocation() << "）：";
			getline(std::cin, location);
			if (location.empty()) location = it->getLocation();
			std::cout << "--书籍总量（" << it->getTotal() << "）：";
			getline(std::cin, total);
			if (total.empty()) total = std::to_string(it->getTotal());
			std::cout << "确定修改吗？(y/n)";
			char choice;
			std::cin >> choice;
			if (choice == 'y') {
				it->setName(name);
				it->setAuthor(author);
				it->setISBN(ISBN);
				it->setPrice(std::stod(price));
				it->setPublisher(publisher);
				it->setPublishDate(publishDate);
				it->setBarcode(barcode);
				it->setClassification(std::stoi(classification));
				it->setLocation(location);
				// 同步更新索引
				bookIndex.erase(mark);//移除原来的索引
				bookIndex[ISBN] = it->getIndex();//添加新的索引，使用找到的书籍的索引
				// 同步更新借阅记录
				for (auto& record : borrowingRecords) 
				{//遍历存储借阅记录的容器 borrowingRecords，如果某一条借阅记录的书籍ISBN等于 mark，则更新它的书籍ISBN为新的 ISBN
					if (record.getBookISBN() == mark) {
						record.setBookISBN(ISBN);
					}
				}
				// 同步更新可借数量
				int distance = std::stoi(total) - it->getTotal();
				it->setTotal(std::stoi(total));//将当前书籍的总量更新为用户输入的值，即将 total 转换为整数后的值 stoi：转换为整数
				it->setAvailable(it->getAvailable() + distance);//同步书籍总量变化

				std::cout << "书籍已成功修改" << std::endl;
			}
			else {
				std::cout << "已取消修改" << std::endl;;
			}
		}
		else {
			std::cout << "找不到要修改的书籍，请重新输入" << std::endl;
		}
	}
}


void Manager::searchBookByName() {
	std::cout << "----------查找书名----------" << std::endl;
	std::cout << "请输入要查找的书名" << std::endl;
	std::string name;
	int count = 0;
	std::vector<Book> tmpBooks;
	std::cin >> name;
	for (auto& book : books) {
		if (book.getName() == name) {
			tmpBooks.push_back(book);//添加到临时容器 tmpBooks
			count++;
		}
	}
	if (count == 0) {
		std::cout << "找不到该书籍" << std::endl;
	}
	else {
		std::cout << "------------------------------------------" << std::endl;
		std::cout << "找到 " << count << " 本书籍" << std::endl;
		showBookTitle();
		for (auto& book : tmpBooks) {
			book.showInfo();
		}
		std::cout << "------------------------------------------" << std::endl;
	}
}

void Manager::searchBookByAuthor() {
	std::cout << "----------查找作者----------" << std::endl;
	std::cout << "请输入要查找的作者" << std::endl;
	std::string author;
	int count = 0;
	std::vector<Book> tmpBooks;
	std::cin >> author;
	for (auto& book : books) {
		if (book.getAuthor() == author) {
			tmpBooks.push_back(book);
			count++;
		}
	}
	if (count == 0) {
		std::cout << "找不到该作者的书籍" << std::endl;
	}
	else {
		std::cout << "------------------------------------------" << std::endl;
		std::cout << "找到 " << count << " 本书籍" << std::endl;
		showBookTitle();
		for (auto& book : tmpBooks) {
			book.showInfo();
		}
		std::cout << "------------------------------------------" << std::endl;
	}
}

void Manager::searchBookByISBN() {
	std::cout << "----------查找 ISBN 号----------" << std::endl;
	std::cout << "请输入要查找的 ISBN 号" << std::endl;
	std::string ISBN;
	std::cin >> ISBN;
	auto it = std::find_if(books.begin(), books.end(), [ISBN](Book& book) {
		return book.getISBN() == ISBN;
		});
	if (it != books.end()) {
		std::cout << "------------------------------------------" << std::endl;
		showBookTitle();
		it->showInfo();
		std::cout << "------------------------------------------" << std::endl;
	}
	else {
		std::cout << "找不到该书籍" << std::endl;
	}
}

void Manager::searchBookByPublisher() {
	std::cout << "----------查找出版社----------" << std::endl;
	std::cout << "请输入要查找的出版社" << std::endl;
	std::string publisher;
	int count = 0;
	std::vector<Book> tmpBooks;
	std::cin >> publisher;
	for (auto& book : books) {
		if (book.getPublisher() == publisher) {
			tmpBooks.push_back(book);
			count++;
		}
	}
	if (count == 0) {
		std::cout << "找不到该出版社的书籍" << std::endl;
	}
	else {
		std::cout << "------------------------------------------" << std::endl;
		std::cout << "找到 " << count << " 本书籍" << std::endl;
		showBookTitle();
		for (auto& book : tmpBooks) {
			book.showInfo();
		}
		std::cout << "------------------------------------------" << std::endl;
	}
}

void Manager::searchBookByBarcode() {
	std::cout << "----------查找条码号----------" << std::endl;
	std::cout << "请输入要查找的条码号" << std::endl;
	std::string barcode;
	std::cin >> barcode;
	auto it = std::find_if(books.begin(), books.end(), [barcode](Book& book) {
		return book.getBarcode() == barcode;
		});
	if (it != books.end()) {
		std::cout << "------------------------------------------" << std::endl;
		showBookTitle();
		it->showInfo();
		std::cout << "------------------------------------------" << std::endl;
	}
	else {
		std::cout << "找不到该书籍" << std::endl;
	}
}

void Manager::searchBookByClassification() {
	std::cout << "----------查找分类号----------" << std::endl;
	std::cout << "请输入要查找的分类号" << std::endl;
	int classification;
	int count = 0;
	std::vector<Book> tmpBooks;
	std::cin >> classification;
	for (auto& book : books) {
		if (book.getClassification() == classification) {
			tmpBooks.push_back(book);
			count++;
		}
	}
	if (count == 0) {
		std::cout << "找不到该分类的书籍" << std::endl;
	}
	else {
		std::cout << "------------------------------------------" << std::endl;
		std::cout << "找到 " << count << " 本书籍" << std::endl;
		showBookTitle();
		for (auto& book : tmpBooks) {
			book.showInfo();
		}
		std::cout << "------------------------------------------" << std::endl;
	}
}

void Manager::searchBookByLocation() {
	std::cout << "----------查找馆藏地----------" << std::endl;
	std::cout << "请输入要查找的馆藏地" << std::endl;
	std::string location;
	int count = 0;
	std::vector<Book> tmpBooks;
	std::cin >> location;
	for (auto& book : books) {
		if (book.getLocation() == location) {
			tmpBooks.push_back(book);
			count++;
		}
	}
	if (count == 0) {
		std::cout << "找不到该馆藏地的书籍" << std::endl;
	}
	else {
		std::cout << "------------------------------------------" << std::endl;
		std::cout << "找到 " << count << " 本书籍" << std::endl;
		showBookTitle();
		for (auto& book : tmpBooks) {
			book.showInfo();
		}
		std::cout << "------------------------------------------" << std::endl;
	}
}

void Manager::borrowBook(std::string borrowerID) {
	std::chrono::system_clock::time_point today = std::chrono::system_clock::now();
	std::time_t tt = std::chrono::system_clock::to_time_t(today);
	std::tm* now = std::localtime(&tt);
	int year = now->tm_year + 1900;
	int month = now->tm_mon + 1;
	int day = now->tm_mday;
	std::string borrowDate = std::to_string(year) + "-" + std::to_string(month) + "-" + std::to_string(day);

	std::cout << "----------借阅书籍----------" << std::endl;
	std::cout << "请输入要借阅的书籍的条码号或 ISBN 码，输入 0 退出" << std::endl;
	std::string mark;
	while (true) {
		std::cin >> mark;
		if (mark == "0") break;
		auto it = std::find_if(books.begin(), books.end(), [mark](Book& book) {
			return book.getBarcode() == mark || book.getISBN() == mark;
			});
		if (it != books.end()) {
			if (it->getAvailable() > 0) {
				std::cout << "确定借阅吗？(y/n)";
				char choice;
				std::cin >> choice;
				if (choice == 'y') {
					it->setAvailable(it->getAvailable() - 1);
					// 判断是条码号还是 ISBN 码
					std::string bookISBN = it->getBarcode() == mark ? it->getISBN() : mark;
					int index = (int)borrowingRecords.size() + 1;
					BorrowingRecord record(bookISBN, borrowerID, borrowDate, index);
					borrowingRecords.push_back(record);
					std::cout << "借阅成功！" << std::endl;
				}
				else {
					std::cout << "已取消借阅" << std::endl;;
				}
			}
			else {
				std::cout << "该书已全部借出" << std::endl;
			}
		}
		else {
			std::cout << "找不到要借阅的书籍，请重新输入" << std::endl;
		}
	}
}

void Manager::returnBook(std::string borrowerID) {
	std::cout << "----------归还书籍----------" << std::endl;
	std::cout << "借阅记录如下：" << std::endl;
	showRecordTitle();
	for (auto& record : borrowingRecords) {
		if (record.getBorrowerID() == borrowerID &&
			(record.getStatus() == "借阅中" || record.getStatus() == "逾期" || record.getStatus() == "今日到期")) {
			record.showInfo(books[bookIndex[record.getBookISBN()] - 1]);        // 通过索引获取书籍信息
		}
	}
	std::cout << "------------------------------------------" << std::endl;
	std::cout << "请输入要归还的借阅记录 ID，输入 0 退出" << std::endl;
	std::string recordID;
	while (true) {
		std::cin >> recordID;
		if (recordID == "0") break;
		auto it = std::find_if(borrowingRecords.begin(), borrowingRecords.end(), [recordID](BorrowingRecord& record) {
			return recordID == record.getID();
			});
		if (it != borrowingRecords.end() || it->getBorrowerID() == borrowerID) {
			if (it->getBorrowerID() == borrowerID &&
				(it->getStatus() == "借阅中" || it->getStatus() == "逾期" || it->getStatus() == "今日到期")) {
				std::cout << "确定归还吗？(y/n)";
				char choice;
				std::cin >> choice;
				if (choice == 'y') {
					it->setStatus("已归还");
					std::chrono::system_clock::time_point today = std::chrono::system_clock::now();
					std::time_t tt = std::chrono::system_clock::to_time_t(today);
					std::tm* now = std::localtime(&tt);
					int year = now->tm_year + 1900;
					int month = now->tm_mon + 1;
					int day = now->tm_mday;
					std::string returnDate =
						std::to_string(year) + "-" + std::to_string(month) + "-" + std::to_string(day);
					it->setReturnDate(returnDate);

					// 同步更新书籍可借数量
					Book& book = books[bookIndex[it->getBookISBN()] - 1];
					book.setAvailable(book.getAvailable() + 1);

					std::cout << "归还成功！" << std::endl;
				}
				else {
					std::cout << "已取消归还" << std::endl;;
				}
			}
			else {
				std::cout << "该借阅记录不可归还" << std::endl;
			}
		}
		else {
			std::cout << "找不到要归还的借阅记录，请正确输入本人的借阅记录 ID" << std::endl;
		}
	}
}

void Manager::renewBook(std::string borrowerID) {
	std::cout << "----------续借书籍----------" << std::endl;
	std::cout << "借阅记录如下：" << std::endl;
	showRecordTitle();
	for (auto& record : borrowingRecords) {
		if (record.getBorrowerID() == borrowerID && (record.getStatus() == "借阅中" || record.getStatus() == "逾期")) {
			record.showInfo(books[bookIndex[record.getBookISBN()] - 1]);        // 通过索引获取书籍信息
		}
	}
	std::cout << "------------------------------------------" << std::endl;
	std::cout << "请输入要续借的借阅记录 ID，输入 0 退出" << std::endl;
	std::string recordID;
	while (true) {
		std::cin >> recordID;
		if (recordID == "0") break;
		auto it = std::find_if(borrowingRecords.begin(), borrowingRecords.end(), [recordID](BorrowingRecord& record) {
			return recordID == record.getID();
			});
		if (it != borrowingRecords.end() || it->getBorrowerID() == borrowerID) {
			if (it->getBorrowerID() == borrowerID &&
				(it->getStatus() == "借阅中" || it->getStatus() == "逾期" || it->getStatus() == "今日到期")) {
				std::cout << "确定续借吗？(y/n)";
				char choice;
				std::cin >> choice;
				if (choice == 'y') {
					it->setStatus("续借中");
					std::cout << "续借成功！" << std::endl;
				}
				else {
					std::cout << "已取消续借" << std::endl;;
				}
			}
			else {
				std::cout << "该借阅记录不可续借" << std::endl;
			}
		}
		else {
			std::cout << "找不到要续借的借阅记录，请正确输入本人的借阅记录 ID" << std::endl;
		}
	}
}

// 显示所有借阅记录
void Manager::displayBorrowingRecords() {
	std::cout << "----------借阅记录----------" << std::endl;
	showRecordTitle();
	for (auto& record : borrowingRecords) {
		record.showInfo(books[bookIndex[record.getBookISBN()] - 1]);        // 通过索引获取书籍信息
	}
}

// 显示特定状态的借阅记录
void Manager::displayBorrowingRecords(std::string status) {
	std::cout << "----------借阅记录----------" << std::endl;
	showRecordTitle();
	for (auto& record : borrowingRecords) {
		if (record.getStatus() == status) {
			record.showInfo(books[bookIndex[record.getBookISBN()] - 1]);        // 通过索引获取书籍信息
		}
	}
}

void Manager::displayBorrowingRecords(std::string status1, std::string status2) {
	std::cout << "----------借阅记录----------" << std::endl;
	showRecordTitle();
	for (auto& record : borrowingRecords) {
		if (record.getStatus() == status1 || record.getStatus() == status2) {
			record.showInfo(books[bookIndex[record.getBookISBN()] - 1]);        // 通过索引获取书籍信息
		}
	}
}


// 获取单例
Manager* Manager::getInstance() {
	if (instance == nullptr) {
		instance = new Manager();
	}
	return instance;
}

void Manager::showRecordTitle() {
	std::cout << std::setfill(' ') << std::setw(20) << std::left << "ID"
		<< std::setfill(' ') << std::setw(16) << std::left << "书名"
		<< std::setfill(' ') << std::setw(18) << std::left << "作者"
		<< std::setfill(' ') << std::setw(15) << std::left << "ISBN 号"
		<< std::setfill(' ') << std::setw(20) << std::left << "读者 ID"
		<< std::setfill(' ') << std::setw(20) << std::left << "借阅日期"
		<< std::setfill(' ') << std::setw(20) << std::left << "归还日期"
		<< std::setfill(' ') << std::setw(20) << std::left << "续借日期"
		<< std::setfill(' ') << std::setw(10) << std::left << "状态"
		<< std::setfill(' ') << std::setw(10) << std::left << "剩余天数"
		<< std::endl;
}

void Manager::showBookTitle() {
	std::cout << std::setfill(' ') << std::setw(10) << std::left << "条码号"
		<< std::setfill(' ') << std::setw(16) << std::left << "书名"
		<< std::setfill(' ') << std::setw(18) << std::left << "作者"
		<< std::setfill(' ') << std::setw(15) << std::left << "ISBN 号"
		<< std::setfill(' ') << std::setw(8) << std::left << "定价"
		<< std::setfill(' ') << std::setw(16) << std::left << "出版社"
		<< std::setfill(' ') << std::setw(20) << std::left << "出版日期"
		<< std::setfill(' ') << std::setw(10) << std::left << "分类号"
		<< std::setfill(' ') << std::setw(10) << std::left << "馆藏地"
		<< std::setfill(' ') << std::setw(10) << std::left << "书籍总量"
		<< std::setfill(' ') << std::setw(10) << std::left << "可借数量"
		<< std::endl;
}

void Manager::displayBook() {
	std::cout << "----------默认显示所有书籍----------" << std::endl;
	showBookTitle();
	for (auto& book : books) {
		book.showInfo();
	}
}

void Manager::displayBookByName() {
	std::cout << "----------按书名顺序显示书籍----------" << std::endl;
	showBookTitle();
	std::vector<Book> tmpBooks = books;
	std::sort(tmpBooks.begin(), tmpBooks.end(), [](Book& book1, Book& book2) {
		return book1.getName() < book2.getName();
		});
	for (auto& book : tmpBooks) {
		book.showInfo();
	}
}

void Manager::displayBookByAuthor() {
	std::cout << "----------按作者顺序显示书籍----------" << std::endl;
	showBookTitle();
	std::vector<Book> tmpBooks = books;
	std::sort(tmpBooks.begin(), tmpBooks.end(), [](Book& book1, Book& book2) {
		return book1.getAuthor() < book2.getAuthor();
		});
	for (auto& book : tmpBooks) {
		book.showInfo();
	}
}

void Manager::displayBookByISBN() {
	std::cout << "----------按 ISBN 号顺序显示书籍----------" << std::endl;
	showBookTitle();
	std::vector<Book> tmpBooks = books;
	std::sort(tmpBooks.begin(), tmpBooks.end(), [](Book& book1, Book& book2) {
		return book1.getISBN() < book2.getISBN();
		});
	for (auto& book : tmpBooks) {
		book.showInfo();
	}
}

void Manager::displayBookByPublisher() {
	std::cout << "----------按出版社顺序显示书籍----------" << std::endl;
	showBookTitle();
	std::vector<Book> tmpBooks = books;
	std::sort(tmpBooks.begin(), tmpBooks.end(), [](Book& book1, Book& book2) {
		return book1.getPublisher() < book2.getPublisher();
		});
	for (auto& book : tmpBooks) {
		book.showInfo();
	}
}

void Manager::displayBookByBarcode() {
	std::cout << "----------按条码号顺序显示书籍----------" << std::endl;
	showBookTitle();
	std::vector<Book> tmpBooks = books;
	std::sort(tmpBooks.begin(), tmpBooks.end(), [](Book& book1, Book& book2) {
		return book1.getBarcode() < book2.getBarcode();
		});
	for (auto& book : tmpBooks) {
		book.showInfo();
	}
}

void Manager::displayBookByClassification() {
	std::cout << "----------按分类号顺序显示书籍----------" << std::endl;
	showBookTitle();
	std::vector<Book> tmpBooks = books;
	std::sort(tmpBooks.begin(), tmpBooks.end(), [](Book& book1, Book& book2) {
		return book1.getClassification() < book2.getClassification();
		});
	for (auto& book : tmpBooks) {
		book.showInfo();
	}
}
